package cn.rongcloud.im.ui.moudle.convenient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.rongcloud.im.R;
import cn.rongcloud.im.ui.moudle.convenient.bean.ConvenientStoreChildBean;

/**
 * Created by lincheng on 2017/3/15.
 */

public class ConvenientStoreChildlAdapter extends RecyclerView.Adapter<ConvenientStoreChildlAdapter.MyViewHolder> {
    /**上下文*/
    private Context mContext;
    /**包含子Bean的List*/
    private List<ConvenientStoreChildBean> mChildBeanList;

    /**
     * 构造函数
     * @param context     上下文
     * @param childBeanList     包含Detail的Bean的List
     */
    public ConvenientStoreChildlAdapter(Context context , List<ConvenientStoreChildBean> childBeanList){
        mContext = context;
        mChildBeanList =childBeanList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_convenient_store_child,null);
        MyViewHolder myViewHolder =new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String storeName ;
        float storeMoneyCount ;
        if(position == 0){
            holder.mStoreTopTextView.setVisibility(View.VISIBLE);
        }else{
            holder.mStoreTopTextView.setVisibility(View.GONE);
        }
        storeName = mChildBeanList.get(position).getStoreName();
        storeMoneyCount =mChildBeanList.get(position).getMoneyCount();
        holder.mStoreNameTextView.setText(storeName);
        holder.mStoreMoneyCountTextView.setText(storeMoneyCount+"");
    }

    @Override
    public int getItemCount() {
        return mChildBeanList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        /**商品个数*/
        TextView mStoreNameTextView ;
        /**商品价格*/
        TextView mStoreMoneyCountTextView;
        /**顶部的商品TextView*/
        TextView mStoreTopTextView;
        public MyViewHolder(View itemView) {
            super(itemView);
            mStoreNameTextView = (TextView) itemView.findViewById(R.id.tv_store_name);
            mStoreMoneyCountTextView = (TextView) itemView.findViewById(R.id.tv_money_count);
            mStoreTopTextView = (TextView) itemView.findViewById(R.id.tv_top_child_item);
        }
    }
}
